from typing import List


class Solution:
    def alertNames(self, keyName: List[str], keyTime: List[str]) -> List[str]:
        keyMinites = self.change_show(keyTime)
        name_dict = {}
        for i in range(len(keyName)):
            name = keyName[i]
            minite = keyMinites[i]
            if name in name_dict:
                name_dict[name].append(minite)
            else:
                name_dict[name] = [minite]

        resList = []
        for name in name_dict.keys():
            miniteList = name_dict[name]
            if len(miniteList) < 3:
                del name_dict[name]
            else:
                miniteList.sort()
                first, second = miniteList[0], miniteList[1]
                for i in range(2, len(miniteList)):
                    minite = miniteList[i]
                    if second < 0:
                        second = minite
                        continue
                    if minite-first <= 60:
                        resList.append(name)
                        break
                    elif minite-second <= 60:
                        first, second = second, minite
                    else:
                        first, second = minite, -1

        resList.sort()
        return resList

    def change_show(self, keyTime: List[str]) -> List[int]:
        minites = []
        for st in keyTime:
            hour, minite = st.split(":")
            minites.append(int(hour)*60+int(minite))

        return minites


print(Solution().alertNames(
    ["a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b"],
    ["04:48", "23:53", "06:36", "07:45", "12:16", "00:52", "10:59", "17:16", "00:36", "01:26", "22:42"]))
